<!DOCTYPE html>
<html>
<head>
   <!-- 页面meta -->
   <meta charset="utf-8">
   <meta http-equiv="X-UA-Compatible" content="IE=edge">
   <title>传智健康</title>
   <meta name="description" content="传智健康">
   <meta name="keywords" content="传智健康">
   <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
   <!-- 引入样式 -->
   <link rel="stylesheet" href="../plugins/elementui/index.css">
   <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
   <link rel="stylesheet" href="../css/style.css">

   <style>
      .el-row {
         margin-bottom: 20px;
      }

      .el-col {
         border-radius: 4px;
      }
   </style>
</head>
<body class="hold-transition">
<div id="app">
   <div class="content-header">
      <h1>健康干预
         <small>人群分类</small>
      </h1>
      <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
         <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
         <el-breadcrumb-item>健康干预</el-breadcrumb-item>
         <el-breadcrumb-item>人群分类</el-breadcrumb-item>
      </el-breadcrumb>
   </div>
   <div class="app-container">
      <div class="box">
         <!--搜索框-->
         <div class="filter-container">
            <el-input placeholder="档案号/姓名" v-model="pagination.queryString" style="width: 200px;"
                      class="filter-item"></el-input>
            <el-button type="primary" class="dalfBut" @click="findPage()">查询</el-button>
         </div>
         <!--搜索框/-->

         <!--分页数据-->
         <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
            <el-table-column type="index" align="center" label="序号"></el-table-column>
            <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
            <el-table-column prop="name" label="姓名" align="center"></el-table-column>
            <el-table-column prop="sex" label="性别" align="center">
               <template slot-scope="scope">
                  <span>{{ scope.row.sex == '1' ? '男' :  '女'}}</span>
               </template>
            </el-table-column>
            <el-table-column prop="age" label="年龄" align="center"></el-table-column>
            <el-table-column label="状态" align="center">
               <template slot-scope="scope">
                  <!--理解:scope.row为固定写法,表示当前行对象,.sex为获取sex属性-->
                  <span>{{ scope.row.categoryStatus == '0' ? '系统预分类' : '人工分类'}}</span>
               </template>
            </el-table-column>
            <el-table-column label="人群分类" align="center">
               <template slot-scope="scope">
                  <span v-for="category in scope.row.categoryList">{{category.categoryName}} </span>
               </template>
            </el-table-column>
            <el-table-column prop="user.realName" label="健康管理师" align="center"></el-table-column>
            <el-table-column label="操作" align="center">
               <template slot-scope="scope">
                  <el-button type="primary" size="mini" @click="handleConfirm(scope.row)">确认分类</el-button>
                  <!--scope.row代表当前行的对象-->
                  <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
               </template>
            </el-table-column>
         </el-table>
         <!--分页数据/-->

         <!--分页条-->
         <div class="pagination-container">
            <el-pagination
               class="pagiantion"
               @current-change="handleCurrentChange"
               :current-page="pagination.currentPage"
               :page-size="pagination.pageSize"
               layout="total, prev, pager, next, jumper"
               :total="pagination.total">
            </el-pagination>
         </div>
         <!--分页条/-->

         <!-- 确认分类 -->
         <div class="add-form">
            <el-dialog v-if="dialogFormVisible4Edit" title="确认分类" :visible.sync="dialogFormVisible4Edit">
               <template>
                  <el-tabs v-model="activeName" @tab-click="handleClick">
                     <!--基本信息-->
                     <el-tab-pane label="基本信息" name="first">
                        <el-row>
                           <el-col :span="12">
                              <el-col :span="4">档案号:</el-col>
                              <el-col :span="20">{{baseData.fileNumber}}</el-col>
                           </el-col>
                           <el-col :span="12">
                              <el-col :span="4">姓名:</el-col>
                              <el-col :span="20">{{baseData.name}}</el-col>
                           </el-col>
                        </el-row>
                        <el-row>
                           <el-col :span="12">
                              <el-col :span="4">年龄:</el-col>
                              <el-col :span="20">{{baseData.age}}</el-col>
                           </el-col>
                           <el-col :span="12">
                              <el-col :span="4">性别:</el-col>
                              <el-col :span="20">{{baseData.sex =='1' ? '男':'女'}}</el-col>
                           </el-col>
                        </el-row>
                        <el-row>
                           <el-col :span="2">疾病史:</el-col>
                           <el-col :span="22">{{baseData.diseaseHis}}</el-col>
                        </el-row>
                        <el-row>
                           <el-col :span="2">遗传史:</el-col>
                           <el-col :span="22">{{baseData.geneticHis}}</el-col>
                        </el-row>
                        <el-row>
                           <el-col :span="2">手术史:</el-col>
                           <el-col :span="22">{{baseData.surgeryHis}}</el-col>
                        </el-row>
                     </el-tab-pane>
                     <!--基本信息/-->
                     <!--体检信息-->
                     <el-tab-pane label="体检信息" name="second">
                        <template>
                           <el-table :data="medicalData" style="width: 100%">
                              <el-table-column prop="fileNumber" label="档案号" width="180"></el-table-column>
                              <el-table-column prop="medical" label="体检日期" width="180"></el-table-column>
                              <el-table-column prop="setmealName" label="体检套餐"></el-table-column>
                              <el-table-column label="查看体检报告" width="120">
                                 <template slot-scope="scope">
                                    <el-button @click="lookMedicalReport(scope.row)" type="text" size="small">查看</el-button>
                                 </template>
                              </el-table-column>
                           </el-table>
                        </template>
                     </el-tab-pane>
                     <!--体检信息/-->
                     <!--评估结果-->
                     <el-tab-pane label="评估结果" name="third">
                        <template>
                           <el-table :data="assessData" style="width: 100%">
                              <el-table-column prop="fileNumber" label="档案号" width="180"></el-table-column>
                              <el-table-column prop="assessTime" label="风险评估日期" width="180"></el-table-column>
                              <el-table-column prop="status" label="问卷状态"></el-table-column>
                              <el-table-column label="查看评估报告" width="120">
                                 <template slot-scope="scope">
                                    <el-button @click="lookAccessReport(scope.row)" type="text" size="small">查看</el-button>
                                 </template>
                              </el-table-column>
                           </el-table>
                        </template>
                     </el-tab-pane>
                     <!--评估结果/-->
                     <!--确认分类-->
                     <el-tab-pane label="确认分类:" name="fourth">
                        <el-row>
                           <el-col :span="4">确认分类</el-col>
                           <el-col :span="20">
                              <el-checkbox-group v-model="checkList">
                                 <el-checkbox v-for="checkName in checkData" :label="checkName"></el-checkbox>
                              </el-checkbox-group>
                           </el-col>
                        </el-row>
                        <el-row>
                           <el-col :span="4">健康管理师:</el-col>
                           <el-col :span="20">
                              <el-select v-model="value" placeholder="请选择">
                                 <el-option
                                    v-for="item in options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                 </el-option>
                              </el-select>
                           </el-col>
                        </el-row>
                     </el-tab-pane>
                     <!--确认分类/-->
                  </el-tabs>
               </template>
               <div slot="footer" class="dialog-footer">
                  <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                  <el-button type="primary" @click="handleEdit()">保存</el-button>
               </div>
            </el-dialog>
         </div>
      </div>
   </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
   var app = new Vue({
      el: '#app',
      data: {
         assessData: [],//评估信息
         medicalData: [],//体检信息
         dataList: [],//列表数据
         options: [{
            value: 1,
            label: '黄金糕'
         }
         ],//健康管理师集合
         value: '',//已选的健康管理师
         checkList: [],//已选中的分类
         checkData: [],//复选框数据集合
         memberId: null,//当前选中会员id
         tableData: [{
            date: '2016-05-02',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1518 弄'
         }, {
            date: '2016-05-04',
            name: '王小虎',
            address: '上海市普陀区金沙江路 1517 弄'
         }],
         activeName: 'first',
         baseData: null,//基本信息数据
         pagination: {//分页相关模型数据
            currentPage: 1,//当前页码
            pageSize: 10,//每页显示的记录数
            total: 0,//总记录数
            queryString: null//查询条件
         },
         dialogFormVisible4Edit: false,//编辑表单是否可见
      },

      //钩子函数，VUE对象初始化完成后自动执行,
      created() {
         //初始化分页查询
         this.findPage();

      },

      methods: {
         lookAccessReport(row) {
            //alert(row.fileNumber);
            //发送ajax,获取文档名
            window.location.href = "/risk/load4PDF/"+row.fileNumber+".do";
         },
         lookMedicalReport(row) {
            //alert(row.fileNumber);
            //发送ajax,获取文档名
            axios.get("/member/findMedicalReport/"+row.fileNumber+".do").then((res) => {
               if (res.data.flag){
                  alert(res.data.data);
                  window.location.href = "http://q9ckvminn.bkt.clouddn.com/"+res.data.data;
               } else {
                  this.$message.error(res.data.message);
               }
            }).catch().finally();
         },
         handleEdit() {
            //1.隐藏窗口
            this.dialogFormVisible4Edit = false;
            //2.封装参数
            var para = {
               memberId : this.memberId,
               checkList : this.checkList,
               healthManagerId:this.value
            };
            //3.发送ajax,修改分类信息
            axios.post("/patientCategory/setCategory.do",para).then((res) => {
               if (!res.data.flag) {
                  this.$message.error(res.data.message);
               }
            }).catch().finally(() =>{
               //调用分页查询
               this.findPage();
            });
         },
         handleClick(tab, event) {
            //console.log(tab, event);
         },
         onSubmit() {

         },

         //分页查询
         findPage(isCustom) { //参数:表示是否定制当前页
            //debugger;
            //0.判断是从查询按钮调用此方法
            if (!isCustom) {//无惨:默认重置当前页
               //将当前页码重置为1
               this.pagination.currentPage = 1;
            }

            //console.log("hello findPage!");//测试
            //1.封装参数,当前页,每页尺寸,查询条件
            var para = {
               currentPage: this.pagination.currentPage,
               pageSize: this.pagination.pageSize,
               queryString: this.pagination.queryString
            };


            //2.发送ajax请求
            axios.post("/patientCategory/findPage.do", para).then(res => {
               this.pagination.total = res.data.total;
               this.dataList = res.data.rows;//赋值表数据
            }).catch(err => {
               console.log(err);
            }).finally();
         },

         // 重置表单
         resetForm() {
            this.formData = {};
            this.baseData = {};
            this.activeName = 'first';
         },

         // 弹出确认窗口
         handleConfirm(row) {//不使用row直接回显,可能其他管理员已经删除了此条数据,故以数据库为准
            //1.设置显示编辑窗口
            this.resetForm();
            this.memberId = row.id;//给表单的会员id赋值
            //2.发送ajax,回显基本信息
            axios.get("/patientCategory/findById/" + row.id + ".do").then((res) => {
               //显示确认窗口
               this.dialogFormVisible4Edit = true;

               if (res.data.flag) {//查询成功
                  //设置回显基本信息数据
                  this.baseData = res.data.data;

               } else {//回显失败原因:多线程同时操作,页面数据已经不存在,故无法回显
                  this.$message.error("获取数据失败,请刷新当前页面")
               }
            }).catch().finally();

            //3.发送ajax,回显体检信息
            axios.get("/order/findByMemberId/" + row.id + ".do").then((res) => {
               //debugger;
               if (res.data.flag) {
                  this.medicalData = res.data.data;
               } else {
                  this.$message.error(res.data.message);
               }
            }).catch().finally();

            //4.发送ajax,回显评估结果数据
            axios.get("/member/findAccessDataById/" + row.id + ".do").then((res) => {
               if (res.data.flag) {
                  this.assessData = res.data.data;
               } else {
                  this.$message.error(res.data.message);
               }
            }).catch().finally();

            //5.发送ajax请求,动态生成分类
            axios.get("/patientCategory/findAll.do").then((res) => {
               if (res.data.flag) {
                  this.checkData = res.data.data;
               } else {
                  this.$message.error(res.data.message);
               }
            }).catch().finally();

            //6.发送ajax,回显当前用户对应的分类名称
            axios.get("/patientCategory/findCategoryNamesByMemberId/" + row.id + ".do").then((res) => {
               if (res.data.flag) {
                  this.checkList = res.data.data;
               } else {
                  this.$message.error(res.data.message);
               }
            }).catch().finally();

            //7.发送ajax请求,回显健康管理师
            axios.get("/user/findAllHealthManager.do").then((res) => {
               if (res.data.flag) {
                  this.options = res.data.data;
               } else {
                  this.$message.error(res.data.message);
               }
            }).catch().finally();
            //8.通过会员id,查询已选的健康管理师id,设置到value
            axios.get("/user/findByMemberId/" + row.id + ".do").then((res) => {
               if (res.data.flag) {
                  this.value = res.data.data;
               } else {
                  this.$message.error(res.data.message);
               }
            }).catch().finally();
         },

         //切换页码
         handleCurrentChange(currentPage) {//当前页更改时回调函数
            //currentPage为新的当前页
            //1.修改当前页数据
            this.pagination.currentPage = currentPage;
            //2.调用分页查询方法
            this.findPage(1); //使用自定义当前页
         },

         // 删除
         handleDelete(row) {//row为当前行json对象

            //确认框
            this.$confirm('确认删除吗?', '提示', {
               confirmButtonText: '确定',
               cancelButtonText: '取消',
               type: 'warning'
            }).then(() => {//点确认,回调
               //发送ajax请求
               axios.delete("/checkItem/delete/" + row.id + ".do").then((res) => {
                  console.log(res.data);//测试
                  //判断是否删除成功
                  if (res.data.flag) {//删除成功
                     //成功框
                     app.$message({
                        message: res.data.message,
                        type: 'success'
                     });

                  } else {//删除失败
                     //失败框
                     this.$message.error(res.data.message);
                  }
               }).catch((err) => {//报错,打印日志
                  console.log(err);
                  //调用方法显示错误信息
                  this.showMessage(err);
               }).finally(() => {//始终执行

                  this.findPage(1);//调用分页查询

               });

            }).catch(() => {//点取消,回调
               //取消框
               this.$message({
                  type: 'info',
                  message: '已取消操作'
               });
            });
         },

         //显示报错时的信息
         showMessage(err) {
            if (err == "Error: Request failed with status code 403") {
               this.$message.error("无访问权限");
            } else {
               this.$message.error("未知错误");
            }
         }

      }
   });
</script>

</html>